using System.Collections;
using System.Collections.Generic;
using BehaviorDesigner.Runtime;
using BehaviorDesigner.Runtime.Tasks;
using QFramework;
using UnityEngine;

namespace HareGame
{
    [TaskCategory("通用")]
    public class Seek : Action
    {
        public string TargetId;
        public PathRange PathRange;
        public EventID EventID;
        public SharedGenericVariable[] Params;

        private AIComponent _ai;

        public override void OnStart()
        {
            base.OnStart();

            _ai = GetComponent<AIComponent>();
            if (_ai == null)
            {
                LogKit.E("不存在AIComponent组建，无法使用Seek行为", gameObject);
            }
            else
            {
                _ai.SetPos(GameEntry.Point.FindNode(TargetId), PathRange);
            }
        }

        public override TaskStatus OnUpdate()
        {
            if (_ai == null)
                return TaskStatus.Failure;

            if (_ai.IsReach)
            {
                if (EventID != EventID.None)
                {
                    GameEntry.Event.Send(EventID, Params);
                }
                return TaskStatus.Success;
            }
            return TaskStatus.Running;
        }
    }
}